package com.lg.wxq.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtils {
	public static long ONEDAYMILLIS = 24 * 60 * 60 * 1000;

	public static String getShowTimeString(Date time) {
		long currentTimeMillis = System.currentTimeMillis();
		Date now = new Date(currentTimeMillis);
		long timeDistance = currentTimeMillis - time.getTime();
		long todayStartMillis = currentTimeMillis - (now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds()) * 1000;
		long yesterdayStartMillis = todayStartMillis - ONEDAYMILLIS;
		if (timeDistance < 1000 * 5) {
			return "刚刚";
		} else if (timeDistance < 1000 * 60) {
			return timeDistance / 1000 + "秒前";
		} else if (timeDistance < 1000 * 60 * 60) {
			return timeDistance / (1000 * 60) + "分钟前";
		} else if (timeDistance < 1000 * 60 * 60 * 3) {
			return timeDistance / (1000 * 60 * 60) + "小时前";
		} else if (time.getTime() > todayStartMillis) {
			return "今天 " + getSimpleDateFormat("HH:mm", time);
		} else if (time.getTime() > yesterdayStartMillis) {
			return "昨天 " + getSimpleDateFormat("HH:mm", time);
		} else {
			return getSimpleDateFormat("yyyy-MM-dd HH:mm", time);
		}
	}
	
	public static String getSimpleDateFormat(String pattern,Date time){
		return new SimpleDateFormat(pattern).format(time);
	}
}
